package com.iweibo.adapter;

import java.util.List;

import com.iweibo.R;
import com.iweibo.bean.UserInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 用户信息展示适配器对象
 * @author nibo
 * @date 2012-10-18
 *
 */
public class UserInfoAdapter extends BaseAdapter {

	private Context context;
	private List<UserInfo> listUsers;
	
	public UserInfoAdapter(Context context, List<UserInfo> listUsers) {
		this.context = context;
		this.listUsers = listUsers;
	}
	
	
	@Override
	public int getCount() {
		return listUsers == null ? 0 : listUsers.size();
	}

	@Override
	public Object getItem(int position) {
		return listUsers == null ? null : listUsers.get(position);
	}

	@Override
	public long getItemId(int position) {
		return listUsers == null ? -1 : listUsers.get(position).getUserId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (null == view) {
			view = LayoutInflater.from(context).inflate(R.layout.user_selected_template, null);
			TextView txtUserName = (TextView)view.findViewById(R.id.txt_user_name);
			UserInfo info = (UserInfo)getItem(position);
			if (null != info.getUserIcon()) {
				ImageView imgUserHead = (ImageView)view.findViewById(R.id.img_user_head);
				imgUserHead.setImageDrawable(info.getUserIcon());
			}
			txtUserName.setText(info.getUserName());
		}
		return view;
	}

}
